Function.prototype.bind = function(scope) {
  var _function = this;
  
  return function() {
    return _function.apply(scope, arguments);
  }
}


DAMN = (typeof DAMN != "undefined")?  DAMN : {};

DAMN.Log = new function () {
	this.element= null;
	
	this.init = function (el) {
	  this.element = $("<div>LOG:<br /></div>").attr({"id":"log"}).css({ "overflow": "auto",  "margin": "0px 20px 0px 20px"});;
		el.append(this.element);
	};
	

	this.debug = function(msg) {
		this.logMsg("DEBUG",msg);
	};
	this.info = function(msg) {
		this.logMsg("INFO",msg);
	};
	this.warn = function(msg) {
		this.logMsg("WARN",msg);
	};
	this.error = function(msg) {
		this.logMsg("ERROR",msg);
		return false;
	};
	this.page = function(msg, data) {
		this.logMsg("ERROR","---[BEGIN]---"+msg);
		
		var row = $("<div></div>");
    row.html(data);
    this.element.append(row);
    
		this.logMsg("ERROR","---[END]---"+msg);
	};
	
	this.logMsg = function (sLevel, msg) {
	   
	  var row = $("<div></div>");
    row.text(this.getCurrentTimeFormatted()+": "+msg);
	
    if (sLevel == "DEBUG") {
      row.css({ "background-color": "#CCCCFF"});
  	} else if (sLevel == "INFO") {
  	  row.css({ "background-color": "#CCFFFF"});
  	} else if (sLevel == "WARN") {
  	   row.css({ "background-color": "yellow"});
  	} else if (sLevel == "ERROR") {
  	   row.css({ "background-color": "#FF7070"});
  	}
  	
  	this.element.append(row);
  	
  	var targetOffset = row.offset().top;
    this.element./*parent().*/animate({scrollTop: targetOffset}, 50);
  };
  
  
  this.getCurrentTimeFormatted = function () {
		var now = new Date();
		var hours = now.getHours();
		var minutes = now.getMinutes();
		var seconds = now.getSeconds()
		//var timeValue = "" + ((hours >12) ? hours -12 :hours);
		//if (timeValue == "0") timeValue = 12;
		var timeValue = "" + hours;
		timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
		timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
		//timeValue += (hours >= 12) ? " PM" : " AM";
		
		return timeValue;
	};

		
};